package io.qar.mq.controller;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

/**
 * @program: qar-cloud
 * @description:
 * @author: yyyyjinying
 * @create: 2023-10-13 10:47
 **/
public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException, UnsupportedEncodingException {
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        producer.setNamesrvAddr("qar2:9876");
        producer.start();

        byte[] bytes = "rockmq".getBytes("utf-8");

        Message msg = new Message("topic1", bytes);
//        msg.putUserProperty("id", "0");

        SendResult send = producer.send(msg, 100000);

        System.out.println(send);
        producer.shutdown();



    }
}
